package cn.wind.xboot.module.web.controller.common;

import cn.hutool.core.util.RandomUtil;
import cn.wind.xboot.core.json.JSON;
import cn.wind.xboot.core.res.ApiResult;
import cn.wind.xboot.core.utils.RSAUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.concurrent.TimeUnit;

/**
 * <p>Title: DynamicController</p>
 * <p>Description: TODO</p>
 *
 * @author xukk
 * @version 1.0
 * @date 2018/8/9
 */
@Controller
@RequestMapping("dynamic")
public class DynamicController {
    @Autowired
    private StringRedisTemplate stringRedisTemplate;
    @GetMapping("rsa")
    @JSON
    public ApiResult rsa(){
        RSAUtil rsaUtil=RSAUtil.build().initKeys();
        String privateKey=rsaUtil.getPrivateKeyBase64();
        String publicKey=rsaUtil.getPublicKeyBase64();
        String randomStr= RandomUtil.randomUUID();
        stringRedisTemplate.opsForValue().set("oauth:token:temp:"+randomStr,privateKey,300, TimeUnit.SECONDS);
        return ApiResult.Custom().success().put("publicKey",publicKey).put("randomStr",randomStr);
    }
}
